package com.xcity.game.activity2.groupbuy.model;

import java.util.LinkedList;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 玩家团购数据
 * @author yang.li
 *
 */
public class GroupBuyData {

	/** 团购积分 */
	@JSONField(name = "0")
	public int score;
	/** 团购券 */
	@JSONField(name = "1")
	public int coupon;
	/** 上次购买日期 */
	@JSONField(name = "2")
	public int lastBuyDay;
//	/** 购买记录 */
//	@JSONField(name = "3")
//	public Map<Integer, BoughtRecord> records;
	/** 积分奖励领取状态 */
	@JSONField(name = "4")
	public int rewardState;
	/** 活动序列号 */
	@JSONField(name = "5")
	public int serial;
	/** 购买记录 */
	@JSONField(name = "6")
	public LinkedList<BoughtRecord> records;
	
	public GroupBuyData() {}
	
	public GroupBuyData(int serial, int lastBuyDay) {
		this.serial = serial;
		this.lastBuyDay = lastBuyDay;
	}
	
	public BoughtRecord newRecord(int id) {
		BoughtRecord br = new BoughtRecord(id);
		if (records == null) {
			records = new LinkedList<BoughtRecord>();
		}
		records.add(br);
		return br;
	}
	
	/** 统计某个商品累计购买次数 */
	public int sizeOf(int id) {
		if (records == null) {
			return 0;
		}
		int c = 0;
		for (BoughtRecord br : records) {
			if (br.id == id) {
				c++;
			}
		}
		return c;
	}
	
//	public BoughtRecord getRecord(int id) {
//		return records != null ? records.get(id) : null;
//	}
//	
//	public BoughtRecord getOrCreateRecord(int id) {
//		BoughtRecord br;
//		if (records == null) {
//			records = new HashMap<>();
//			records.put(id, br = new BoughtRecord(/*id*/));
//		} else if ((br = records.get(id)) == null) {
//			records.put(id, br = new BoughtRecord(/*id*/));
//		}
//		return br;
//	}
	
}
